package com.chenjt.jvm.first.seven_directMemory;

import java.nio.ByteBuffer;
import java.util.Scanner;

/**
 * 注释：
 * 查看直接内存的占用与释放
 *
 * IO                   NIO(New IO / Non-Blocking IO)
 * byte[] / char[]      Buffer
 * Stream               Channel
 *
 * @author chenjt
 * @date 2025/6/12 8:39
 */
public class BufferTest {


    private static final int BUFFER = 1024 * 1024 * 1024;// 1GB

    public static void main(String[] args) {
        // 直接分配本地内存空间
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER);
        System.out.println("直接内存分配完毕，请求指示！");

        Scanner scanner = new Scanner(System.in);
        scanner.next();

        System.out.println("开始释放直接内存！");
        byteBuffer = null;
        System.gc();
        scanner.next();
    }

}
